﻿@{
    ViewBag.Title = "News";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div ng-controller="EditableRowCtrl">
    <div class="row">
        <div class=" col-md-6">
            <div class="form-group location-form">
                <label>Choose Location</label>
                <select class="form-control" ng-model="myLocation" ng-options="location.name for location in locations"
                        ng-change="loadNews()">
                </select>
            </div>
            
            <div class="form-group category-form">
                <label>Choose Category</label>
                <select class="form-control" ng-model="myCategory" ng-options="category.name for category in categories"
                        ng-change="loadNews()">
                </select>
            </div>
        </div>
    </div>
    <a class="btn btn-default" href="/News/Create">Add News</a>
    <table class="table table-bordered table-hover table-condensed">
        <tr style="font-weight: bold">
            <td style="width: 25%">Title</td>
            <td style="width: 25%">Action</td>
        </tr>
        <tr ng-repeat="newsItem in news">
            <td>
                <!-- editable (text with validation) -->
                <span>{{newsItem.title}}
                </span>
            </td>
            <td style="white-space: nowrap">
                <!-- form -->
                <div class="buttons" ng-show="!rowform.$visible">
                    <a class="btn btn-primary" href="/News/Edit/{{newsItem.id}}">Edit </a>
                    <a class="btn btn-danger" data-toggle="modal" data-target="#myModal-{{$index}}">Delete</a>
                </div>
                <div class="modal fade" id="myModal-{{$index}}">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title">Confirm</h4>
                            </div>
                            <div class="modal-body">
                                <p>Are you sure to delete?</p>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
                                <button type="button" class="btn btn-primary" ng-click="removeNews($index)">Yes</button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </td>
        </tr>
    </table>

    <a class="btn btn-default load-more" ng-click="loadNews()">Load More</a>
</div>

@section scripts{
    <script type="text/javascript" src="/Scripts/app/news.js"></script>
}